
import java.awt.event.*;

import java.awt.*;
import javax.swing.*;



public class GUINewPatient extends JPanel {
	
	JPanel panel;
	JPanel centerbox;
	JPanel south;
	JTextField fName;
	JTextField lName;
	JTextField addr;
	JTextField user;
	JTextField pw;
	JLabel welcome;
	JButton pat;
	JButton nur;
	JButton doc;
	Member current;
	MemberData a;
	GUIDoctor guiDoc;
	
	public GUINewPatient(Member m, MemberData list, GUIDoctor gd)
	{
		guiDoc = gd;
		current = m;
		a = list;
		
		panel = new JPanel();
		panel.setLayout(new BorderLayout());
		
		centerbox = new JPanel();
		centerbox.setLayout(new BoxLayout(centerbox, BoxLayout.Y_AXIS));
		
		south = new JPanel();
		
		
		welcome = new JLabel("Create New User");
		
		fName = new JTextField("First Name");
		lName = new JTextField("Last Name");
		addr = new JTextField("Address");
		user = new JTextField("Username");
		pw = new JTextField("Password");
		
		pat = new JButton("Create Patient");
		nur = new JButton("Create Nurse");
		doc = new JButton("Create Doctor");
		
		panel.add(welcome, BorderLayout.NORTH);
		centerbox.add(fName);
		centerbox.add(lName);
		centerbox.add(addr);
		centerbox.add(user);
		centerbox.add(pw);
		panel.add(centerbox, BorderLayout.CENTER);
		south.add(doc);
		south.add(nur);
		south.add(pat);
		panel.add(south, BorderLayout.SOUTH);
		this.add(panel);
		
		NewPatientListener npl = new NewPatientListener();
		pat.addActionListener(npl);
		

		NewNurseListener nnl = new NewNurseListener();
		nur.addActionListener(nnl);
		
		

		NewDoctorListener ndl = new NewDoctorListener();
		doc.addActionListener(ndl);
		
		
	}
	
	
	//creates a new patient object in the list of members
	private class NewPatientListener implements ActionListener
	{
		public void actionPerformed(ActionEvent event)
		{
			if(a.getMember(user.getText()) == null)
			{
				Member temp = new Patient(fName.getText(), lName.getText(), pw.getText(), user.getText(), addr.getText(), a.getSize());
				a.addMember(temp);
				
				if(current instanceof Doctor)
				{
					((Doctor)current).addPatient((Patient)temp);
				}
				else
				{
					((Nurse)current).addPatient((Patient)temp);
					
				}
				
				
				welcome.setText("Patient Created!");
				
				fName.setText("First Name");
				lName.setText("Last Name");
				addr.setText("Address");
				user.setText("Username");
				pw.setText("Password");	
                                guiDoc.updatefull();	
			}
			else
			{
				welcome.setText("Username taken");
			}
			
		}
		
	}
	
	
	//creates a new nurse object in the list of members
	private class NewNurseListener implements ActionListener
	{
		public void actionPerformed(ActionEvent event)
		{
			if(a.getMember(user.getText()) == null)
			{
				Member temp = new Nurse(fName.getText(), lName.getText(), pw.getText(), user.getText(), addr.getText(), a.getSize());
				a.addMember(temp);	
				welcome.setText("Nurse Created!");
				
				fName.setText("First Name");
				lName.setText("Last Name");
				addr.setText("Address");
				user.setText("Username");
				pw.setText("Password");
                                guiDoc.updatefull();
				
			}
			
			else
			{
				welcome.setText("Username taken");
				
			}
			
		}
	}
	
	//creates a new doctor object in the list of members
	private class NewDoctorListener implements ActionListener
	{
		public void actionPerformed(ActionEvent event)
		{
			if(a.getMember(user.getText()) == null)
			{
				Member temp = new Doctor(fName.getText(), lName.getText(), pw.getText(), user.getText(), addr.getText(), a.getSize());
				a.addMember(temp);	
				welcome.setText("Doctor Created!");
				
				fName.setText("First Name");
				lName.setText("Last Name");
				addr.setText("Address");
				user.setText("Username");
				pw.setText("Password");	
                                guiDoc.updatefull();
				
			}
			
			else
			{
				welcome.setText("Username taken");
				
			}
			
		}
	}

}
